package org.jeecg.modules.xl.home.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.xl.home.query.HomeQuery;
import org.jeecg.modules.xl.home.service.HomeService;
import org.jeecg.modules.xl.home.vo.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 首页接口
 * @Author: lh
 * @Date:   2025-01-25
 * @Version: V1.0
 */
@Api(tags="首页")
@RestController
@RequestMapping("/xl/home")
public class HomeController {
    @Resource
    private HomeService homeService;

    /**
     * 今日订单数据 查询
     * @param req
     * @return
     */
    @ApiOperation(value="今日订单数据", notes="今日订单数据")
    @GetMapping(value = "/queryDayData")
    public Result<HomeDayDataVO> queryDayData(
                                              HttpServletRequest req) {
        return Result.OK(homeService.queryDayData());
    }

    /**
     * 订单统计信息 查询
     * @param req
     * @return
     */
    @ApiOperation(value="订单统计信息", notes="订单统计信息")
    @GetMapping(value = "/queryOrderData")
    public Result<HomeDataVO> queryOrderData(HomeQuery query,
                                             HttpServletRequest req) {
        return Result.OK(homeService.queryOrderData(query));
    }

    /**
     * 门店销售排行 查询
     * @param req
     * @return
     */
    @ApiOperation(value="门店销售排行", notes="门店销售排行")
    @GetMapping(value = "/storeRanking")
    public Result<IPage<HomeStoreListVO>> storeRanking(HomeQuery query,
                                                       @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                       @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                       HttpServletRequest req) {
        Page page = new Page(pageNo, pageSize);
        IPage<HomeStoreListVO> iPage = homeService.storyRanking(page, query);
        for (int i = 0; i < iPage.getRecords().size(); i++) {
            iPage.getRecords().get(i).setSort(i+1);
        }
        return Result.OK(iPage);
    }


    /**
     * 商品销售排行 查询
     * @param req
     * @return
     */
    @ApiOperation(value="商品销售排行", notes="商品销售排行")
    @GetMapping(value = "/productRanking")
    public Result<IPage<HomeProductListVO>> productRanking(HomeQuery query,
                                                           @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                           @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
            HttpServletRequest req) {
        Page page = new Page(pageNo, pageSize);
        return Result.OK(homeService.productRanking(page,query));
    }


    /**
     * 售后统计信息 查询
     * @param req
     * @return
     */
    @ApiOperation(value="售后统计信息", notes="售后统计信息")
    @GetMapping(value = "/aftersaleData")
    public Result<HomeAftersaleVO> aftersaleData(HomeQuery query,
            HttpServletRequest req) {
        return Result.OK(homeService.aftersaleData(query));
    }
}
